package com.tfswx.jcyw.ruleenginedesigner.service.impl;

import com.tfswx.ruleengine.compute.exception.AppException;
import com.tfswx.jcyw.ruleenginedesigner.dto.stgxgl.StgxAddInputDTO;
import com.tfswx.jcyw.ruleenginedesigner.dto.stgxgl.StgxDeleteInputDTO;
import com.tfswx.jcyw.ruleenginedesigner.dto.stgxgl.StgxListByXmbmQueryInputDTO;
import com.tfswx.jcyw.ruleenginedesigner.dto.stgxgl.StgxListByXmbmQueryOutputDTO;
import com.tfswx.ruleengine.compute.util.CommonUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.tfswx.jcyw.ruleenginedesigner.dao.model.GzyqXtStgx;
import com.tfswx.jcyw.ruleenginedesigner.dao.GzyqXtStgxMapper;
import com.tfswx.jcyw.ruleenginedesigner.service.StgxService;

import java.util.Date;
import java.util.List;

@Service
public class StgxServiceImpl implements StgxService {

    @Resource
    private GzyqXtStgxMapper gzyqXtStgxMapper;

    @Override
    public List<StgxListByXmbmQueryOutputDTO> queryStgxListByXmbm(StgxListByXmbmQueryInputDTO stgxListByXmbmQueryInputDTO) {
        GzyqXtStgx gzyqXtStgx = new GzyqXtStgx();
        BeanUtils.copyProperties(stgxListByXmbmQueryInputDTO, gzyqXtStgx);
        return gzyqXtStgxMapper.queryStgxListByXmbm(gzyqXtStgx);
    }

    @Override
    public boolean addStgx(StgxAddInputDTO stgxAddInputDTO) {
        GzyqXtStgx gzyqXtStgx = new GzyqXtStgx();
        BeanUtils.copyProperties(stgxAddInputDTO, gzyqXtStgx);
        gzyqXtStgx.setGxbm(CommonUtil.getUuid());
        gzyqXtStgx.setSfsc("N");
        gzyqXtStgx.setCjsj(new Date());
        gzyqXtStgx.setZhxgsj(new Date());
        int i = gzyqXtStgxMapper.insert(gzyqXtStgx);
        if (i != 1) {
            throw new AppException("添加失败");
        }
        return true;
    }

    @Override
    public boolean deleteStgx(StgxDeleteInputDTO stgxDeleteInputDTO) {
        GzyqXtStgx gzyqXtStgx = new GzyqXtStgx();
        BeanUtils.copyProperties(stgxDeleteInputDTO, gzyqXtStgx);
        gzyqXtStgx.setZhxgsj(new Date());
        int i = gzyqXtStgxMapper.delete(gzyqXtStgx);
        if (i != 1) {
            throw new AppException("删除失败");
        }
        return true;
    }

}
